package com.sxfq.loansupermarket.app.index.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.sxfq.loansupermarket.app.constants.AppConstant;
import com.sxfq.loansupermarket.app.dto.AppResponseResult;
import com.sxfq.loansupermarket.app.index.service.IndexService;

/**
 * 首页控制器
 * 
 * 
 * Module:
 * 
 * IndexController.java
 * 
 * @author 程盼
 * @since JDK 1.8
 * @version 1.0
 * @description: <描述>
 */
@Controller
@RequestMapping(value = "/index")
public class IndexController {

	private Logger logger = Logger.getLogger(IndexController.class);

	@Resource
	private IndexService indexService;

	@Value("${cms.bannar}")
	private String bannar;

	@Value("${cms.helpCenter}")
	private String helpCenter;

	/**
	 * 首页bannar
	 */
	@RequestMapping(value = "getBannar")
	@ResponseBody
	public AppResponseResult getBannar(HttpServletRequest request, HttpServletResponse response) {
		AppResponseResult result = new AppResponseResult();
		try {
			logger.info("【IndexController.getBannar】channelId:" + bannar);// 栏目ID
			List<Map<String, Object>> list = indexService.getBannar(bannar);
			logger.info("【IndexController.getBannar】list:" + JSONArray.toJSONString(list));
			result.setCode(AppConstant.Code.SUCCESS);
			result.setMsg(AppConstant.Msg.SUCCESS);
			result.setResult(list);
		} catch (Exception e) {
			result.setCode(AppConstant.Code.ERROR);
			result.setMsg(AppConstant.Msg.ERROR);
			result.setResult("");
			logger.error("【IndexController.getBannar】异常", e);
		}
		return result;
	}

	/**
	 * 帮助中心
	 */
	@RequestMapping(value = "getHelpCenter")
	@ResponseBody
	public AppResponseResult getHelpCenter(HttpServletRequest request, HttpServletResponse response) {
		AppResponseResult result = new AppResponseResult();
		try {
			logger.info("【IndexController.getHelpCenter】channelId:" + helpCenter);
			List<Map<String, Object>> list = indexService.getHelpCenter(helpCenter);
			logger.info("【IndexController.getHelpCenter】list:" + JSONArray.toJSONString(list));
			result.setCode(AppConstant.Code.SUCCESS);
			result.setMsg(AppConstant.Msg.SUCCESS);
			result.setResult(list);
		} catch (Exception e) {
			result.setCode(AppConstant.Code.ERROR);
			result.setMsg(AppConstant.Msg.ERROR);
			result.setResult("");
			logger.error("【IndexController.getHelpCenter】异常", e);
		}
		return result;
	}

}
